const express=require("express");
const bodyParser=require("body-parser")

let app=express();
let port=7878
app.listen(port,(err)=>{
    if(!err) console.log(`监听端口在${port}`)
})
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({extended:true}))
app.all("*", function (req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type");
    res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
    res.header("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
    if (req.method.toLowerCase() == 'options')
        res.sendStatus(200);  //让options尝试请求快速结束
    else
        return next();
})

// 登录注册接口
let {login}=require("./user/login")
let {register}=require("./user/register")
//谁来过接口
let {person} =require("./person/person")
//留言板存数据接口
let {getMessage}=require("./message/message") 
//留言取数据接口
let {takeMsg}=require("./message/takeMsg")
//文章接口
let {article}=require("./article/article")
//文章存储留言接口
let  {detailmsg}=require("./detailmsg/detailmsg")
//文章获取留言接口
let {findDetailmsg}=require("./detailmsg/findDetailmsg")
//修改浏览量接口
let {getnum}=require("./article/atcnum")
//搜索文章接口
let {atcSearch}=require("./atcsearch/atcsearch")
//日记接口
let {diary}=require("./diary/diary")

app.post("/user/login",login)
app.post("/user/register",register)
app.get("/person",person)
app.post("/message",getMessage)
app.get("/takemsg",takeMsg)
app.get("/article",article)
app.post("/detailmsg",detailmsg)
app.post("/finddetailmsg",findDetailmsg)
app.post("/atcnum",getnum)
app.post("/atcsearch",atcSearch)
app.get("/diary",diary)